package com.edu.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.edu.api.entity.common.ResponseDTO;
import com.edu.api.entity.common.TimeUtil;
import com.edu.api.entity.order.UserCourseOrder;
import com.edu.order.service.UserCourseOrderService;
import com.edu.order.mapper.UserCourseOrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;


/**
 *
 */
@Service
public class UserCourseOrderServiceImpl extends ServiceImpl<UserCourseOrderMapper, UserCourseOrder>
    implements UserCourseOrderService {

    @Autowired
    private UserCourseOrderMapper userCourseOrderMapper;

    /**
     * 修改用户课程订单表信息
     * @param orderNo
     * @param status
     * @return
     */
    @Override
    public int updateUserCourseOrder(String orderNo,Byte status) {
        QueryWrapper<UserCourseOrder> wq = new QueryWrapper<>();
        wq.eq("order_no",orderNo);
        UserCourseOrder userCourseOrder = new UserCourseOrder();
        userCourseOrder.setStatus(status);
        userCourseOrder.setUpdateTime(TimeUtil.getTimeDate());
        return userCourseOrderMapper.update(userCourseOrder,wq);
    }

    /**
     * 添加用户课程订单表信息
     * @param orderNo
     * @param userId
     * @param courseId
     * @return
     */
    @Override
    public int addUserCourseOrder(String orderNo,Integer userId,Integer courseId) {
        UserCourseOrder userCourseOrder = new UserCourseOrder();
        userCourseOrder.setOrderNo(orderNo);
        userCourseOrder.setUserId(userId);
        userCourseOrder.setCourseId(courseId);
        userCourseOrder.setSourceType((byte)1);
        userCourseOrder.setStatus((byte)0);
        userCourseOrder.setCreateTime(TimeUtil.getTimeDate());
        return userCourseOrderMapper.insert(userCourseOrder);
    }

    @Override
    public ResponseDTO insertCourseOrder(String orderNo, Integer userId, Integer courseId) {
        UserCourseOrder userCourseOrder = new UserCourseOrder();
        userCourseOrder.setOrderNo(orderNo);
        userCourseOrder.setUserId(userId);
        userCourseOrder.setCourseId(courseId);
        userCourseOrder.setSourceType((byte) 1);
        userCourseOrder.setCreateTime(TimeUtil.getTimeDate());
        userCourseOrderMapper.insert(userCourseOrder);
        return null;
    }
}




